package edu.uis.project.frankszoo.model.game;

import java.util.ArrayList;
import java.util.List;

import edu.uis.project.frankszoo.model.card.Card;

/**
 * This class represents a hand in the game
 * 
 */
public class GameHand {

	protected int handNo; // The Hand Number within the game
	protected String dealerID; // The ID of the Dealer
	protected List<ActivePlayer> activePlayers; // A list containing an Active Player instance for every player actively playing in the hand
	protected GameHandTable gameHandTable; // The cards that comprise the ranking set as well as cards that have been outranked within the hand
	protected List<GameRound> gameRounds; // The list containing a GameRound instance for every round played in the current hand.

	/**
	 * This is the constructor for the GameHand
	 * 
	 * @param handNo
	 *            The Hand Number within the game
	 * 
	 */
	public GameHand(int handNo) {
		setHandNo(handNo);
		gameHandTable = new GameHandTable();
		gameRounds = new ArrayList<GameRound>();
	}

	/**
	 * Changes the hand to this hand number
	 * 
	 * @param handNo
	 *            This is the integer variable representing the hand number
	 */
	public void setHandNo(int handNo) {
		this.handNo = handNo;
	}

	/**
	 * Gets the number of this hand.
	 * 
	 * @return handNo This hand number
	 */
	public int getHandNo() {
		return this.handNo;
	}

	/**
	 * Changes the ID of the dealer of this hand.
	 * 
	 * @param dealerID
	 *            The ID of the Dealer
	 */
	public void setDealerID(String dealerID) {
		this.dealerID = dealerID;
	}

	/**
	 * Gets the ID of this dealer.
	 * 
	 * @return dealerID The dealer ID of this hand.
	 */
	public String getDealerID() {
		return this.dealerID;
	}

	/**
	 * Changes the active players list to this player
	 * 
	 * @param activePlayers
	 *            List containing an Active Player instance for every player actively playing in the hand
	 */
	public void setActivePlayers(List<ActivePlayer> activePlayers) {
		this.activePlayers = activePlayers;
	}

	/**
	 * Gets the active players of this hand
	 * 
	 * @return activePlayers List containing an Active Player instance for every player actively playing in the hand
	 */
	public List<ActivePlayer> getActivePlayers() {
		return this.activePlayers;
	}

	/**
	 * Adds the players who are active in the hand
	 * 
	 * @param activePlayer
	 *            Player added in the hand
	 */
	public void addActivePlayer(ActivePlayer activePlayer) {
		this.activePlayers.add(activePlayer);
	}

	/**
	 * Removes the inactive players of this hand from the list
	 * 
	 * @param playerName
	 *            Name of the player removed
	 */
	public void removeActivePlayer(String playerName) {
		for (ActivePlayer player : activePlayers) {
			if (player.getPlayerName().equals(playerName)) {
				activePlayers.remove(player);
			}
		}
	}

	/**
	 * Changes the Game hand table to this game hand table that has the ranking and outranked set of cards.
	 * 
	 * @param gameHandTable
	 *            The cards that comprise the ranking set as well as cards that have been outranked within the hand
	 */
	public void setGameHandTable(GameHandTable gameHandTable) {
		this.gameHandTable = gameHandTable;
	}

	/**
	 * Gets the game hand table of this hand.
	 * 
	 * @return gameHandTable The cards that comprise the ranking set as well as cards that have been outranked within the hand
	 */
	public GameHandTable getGameHandTable() {
		return this.gameHandTable;
	}

	/**
	 * Adds an instance of the Round to the GameRound List
	 * 
	 * @param gameRound
	 *            The Round
	 */
	public void addGameRound(GameRound gameRound) {
		this.gameRounds.add(gameRound);
	}

	/**
	 * Gets this Round of the game
	 * 
	 * @return gameRound The Round
	 */
	public List<GameRound> getGameRounds() {
		return this.gameRounds;
	}

	/**
	 * This method returns the PlayerID of the last active player. It is invoked at the end of the hand
	 * 
	 * @return String PlayerID of the last activePlayer
	 */
	public String getEndingPlayerID() {
		return getActivePlayers().get(0).getPlayerID();
	}

}
